﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Web.Mvc
{
    public sealed class CookieValueProvider : IValueProvider
    {

        ControllerContext Context;

        internal CookieValueProvider(ControllerContext controllerContext)
        {
            this.Context = controllerContext;
        }


        #region IValueProvider 成员

        public bool ContainsPrefix(string prefix)
        {
            return Context.HttpContext.Request.Cookies.AllKeys.Contains(prefix);
        }

        public ValueProviderResult GetValue(string key)
        {
            HttpCookie cookie = Context.HttpContext.Request.Cookies[key];
            return new ValueProviderResult(cookie.Value, cookie.Value, Globalization.CultureInfo.CurrentCulture); 
        }

        #endregion
    }
}
